namespace Collaboris.Saf.Actions.Wss.Tests.Generated
{
    using System;

    using Engine.Report;

    using Microsoft.SharePoint.Administration;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Saf.Tests;
    using Entities;

    using SharePoint.Wss.WebApplications;

    using Utils;

    using Wss.WebApplication;

    /// <summary>
    /// This test was originally generated but has now been tested and verfiied by MJ
    /// </summary
    [TestClass]
    public class CreateWebApplicationTest
    {

        [TestMethod]
        public void CreateWebApplication_Test()
        {
            WSSTestAssistant<CreateWebApplication, WebApplicationInfo> createwebapplication =
                    new WSSTestAssistant<CreateWebApplication, WebApplicationInfo>();

            using (createwebapplication)
            {
                ADHelper.DeleteUserAccount("UnitTester2");
                ADHelper.CreateUserAccount("UnitTester2", "abcde_1234", "Unit Tester", false);

                createwebapplication.FirstEntity.AppPoolUserName = Environment.UserDomainName + @"\UnitTester2";
                createwebapplication.FirstEntity.AppPoolPassword = "abcde_1234";
                createwebapplication.FirstEntity.AppPoolId = "Unit Test App Pool";

                MacroReport doReport = createwebapplication.DoMacro();

                SPWebApplication webApp =
                    SPWebApplicationHelper.GetWebAppFromName(createwebapplication.FirstEntity.WebAppName);

                Assert.IsNotNull(webApp);
                Assert.IsTrue(webApp.ApplicationPool.DisplayName == createwebapplication.FirstEntity.AppPoolId);
                
                // now this tests the Extend Web Application Action too.
                WSSTestAssistant<ExtendWebApplication, ExtendedWebApplicationInfo> extendwebapplication =
                    new WSSTestAssistant<ExtendWebApplication, ExtendedWebApplicationInfo>();

                using (extendwebapplication)
                {
                    MacroReport doReportExtend = extendwebapplication.DoMacro();

                    Assert.IsTrue(System.IO.Directory.Exists(extendwebapplication.FirstEntity.RootDirectory));

                    MacroReport undoReportExtend = extendwebapplication.UndoMacro();

                }

                MacroReport undoReport = createwebapplication.UndoMacro();

                Assert.IsNull(SPWebApplicationHelper.GetWebAppFromName(createwebapplication.FirstEntity.WebAppName));

            }
        }

    }
}
